<template>
  <div class="container">
    <div class="main">
      <div class="leftside">
        <Leftside></Leftside>
      </div>
      <div class="center">
        <div class="heade">文章归档</div>
        <el-card style="width: 800px; text-align: center; min-height: 80vh">
          <el-timeline>
            <el-timeline-item v-for="item in articledata" :key="item._id" :timestamp="$moment(item.time).format('YYYY-MM-DD')" placement="top">
              <el-card>
                <h4>{{item.title}}</h4>
                <span style="color: #409EFF;">类型：{{item.type}}</span>
                <div>
                  <img :src="item.pic" alt="" style="with:50px; height:50px;object-fit: cover;">
                </div>
                <p>{{item.author || '爱吃罗非鱼'}} 提交于 {{$moment(item.time).format('YYYY-MM-DD')}}</p>
              </el-card>
            </el-timeline-item>
          </el-timeline>
          <el-pagination
            background
            layout="prev, pager, next"
            :page-size="pagination.size"
            @current-change="hanldlecurrent"
            v-model="pagination.currentpage"
            :total="pagination.count">
          </el-pagination>
        </el-card>
      </div>
      <div class="rightside">
        <RightsideVue :data="articledata"></RightsideVue>
      </div>
    </div>
  </div>
</template>

<script setup>
import Leftside from '@/components/Leftside.vue'
import Listitem from '@/components/Listitem.vue'
import {searchdata} from "../../apis/article";
import RightsideVue from '@/components/Rightside.vue'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router';
const route = useRoute()
onMounted(()=>{
  getarticledata()
})
const articledata = ref([])
const getarticledata = () =>{
  let params = {
    page: pagination.value.currentpage,
    size: pagination.value.size
  }
  searchdata(params).then((res)=>{
    if (res.data.isok) {
      articledata.value = res.data.data
      console.log(articledata.value, 'data')
      pagination.value.count = res.data.count
    }
  })
}
const pagination = ref({
  currentpage: 1,
  size: 10,
  count: 0
})
const hanldlecurrent = (page) => {
  pagination.value.currentpage = page
  getarticledata()
}
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  min-height: 100vh;
  margin-top: 60px;
  background-color: #f5f5ff;
  .main {
    display: flex;
    justify-content: center;
    .center {
      padding: 0 20px;
      .heade{
        height: 50px;
        line-height: 50px;
        background-color: #fff;
        color: #000;
        text-align: center;
        font-size: 24px;
        padding: 10px;
        box-shadow: #303133 0px 0px 5px;;
        margin: 10px 0;
      }
    }
  }
  .time{
    margin-top: 10px;
  }
}
</style>

